package p3.entity;

import p3.util.Tool;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

public class Car {
    private String carNo;
    private Date startTime;
    private Date endTime;
    private List costs=new ArrayList();
    private int index=-1;//车位号

    public int cost(ParkingArea area){
        int time= Tool.getSecond(this.startTime,new Date());
        int money=Tool.getParkingCost(time);

        costs.add(money);
        area.getLots()[this.index].setCar(null);
        this.index=-1;
        return money;
    }

    public void parking(ParkingArea area){
        Random random=new Random();
        //int index=0;
        while (true) {
            index = random.nextInt(100);
            ParkingLot lot = area.getLots()[index];
            if (lot.getCar()==null){
                lot.setCar(this);
                this.setStartTime(new Date());
                break;
            }
        }
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public String getCarNo() {
        return carNo;
    }

    public void setCarNo(String carNo) {
        this.carNo = carNo;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public List getCosts() {
        return costs;
    }

    public void setCosts(List costs) {
        this.costs = costs;
    }
}
